/* $Id: game.h jjs $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/
#ifndef __GAME_H
#define __GAME_H

#include <vector>
#include <map>
#include "party.h"
#include "../general/channel.h"

/// The different choices for limits to people joining the game

enum join_type {
	Open,
	Moderated,
	Spectators,
	Private
};

/// The different game goals possible

enum goal_type {
	Mayor_player,
	Time,
	Victory_points,
	Target_city,
	Target_city_and_time
};

/// Public information on a game

#define state_defining 0
#define state_editor 1
#define state_game 2
#define state_pauzed 3
#define state_winner 4
#define state_finished 5

class game {
  public:
	long id;                ///< Number of this game
	long timestamp;         ///< Last changes to this game
	std::string name;       ///< Name of this game
	std::string description;///< General promotion of this game
	std::string owner;      ///< Name of the user that created this game
	int join;               ///< Selection in the member join choices
	std::string join_str(); ///< String version of the use join method
	int goal;               ///< Selection in the game goal choices
	std::string goal_str(); ///< String version of the game goal
	std::string map;        ///< Name of the map of this game
	std::string url;        ///< The identification of the game server
	std::string session;    ///< Session of the game on the central server
	int state;              ///< Current state of the game
	vector<party> parties;  ///< List of parties in this game

	/// Send the game data
	void save(channel *ch);
	void server_save(channel *ch); ///< Write data that is needed for the server
};

/// List of current games on number
extern map<long,game> games;

/// Last given out game number
extern long game_number;

/// Array with the string names of the join choices
extern const char* join_types[];

/// Number of join choices
extern const int join_elms;

/// Array with the string names of the goal choices
extern const char* goal_types[];

/// Number of goal choices
extern const int goal_elms;

/// Get the game data from this channel
/**
 \return the number on success or 0 on failure
*/
long load_game(channel *ch);

/// Get the data from a specific game
game get_game(long id);

#endif
